//
//  NewSettingController.swift
//  newShaohuoRen
//
//  Created by hujinbiao on 2018/3/24.
//  Copyright © 2018年 hujinbiao. All rights reserved.
//

import UIKit
import SwiftProgressHUD

class NewSettingController: UITableViewController {
    
    @IBOutlet weak var recoderSwitch: UISwitch!
    @IBOutlet weak var recoderLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "新消息通知"
        
        recoderSwitch.isOn = UserNotificationSettingModel.sharedInstance.is_voice_off!
        if UserNotificationSettingModel.sharedInstance.is_voice_sex == "new_order" {
            recoderLabel.text = "男声"
        }else {
            recoderLabel.text = "女声"
        }
        
    }
    
    @IBAction func recoderSwitchAction(_ sender: UISwitch) {
        
        if sender.isOn {
            UserNotificationSettingModel.sharedInstance.is_voice_off = true
        }else {
            UserNotificationSettingModel.sharedInstance.is_voice_off = false
        }

    }
}

extension NewSettingController {
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 20
    }
    
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.001
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        
        if indexPath.row==1 {
            if !(recoderSwitch.isOn) {
                SwiftProgressHUD.showOnlyText("请打开语音提醒按钮")
                return
            }
            let board = UIStoryboard(name: "VoiceTypeController", bundle: nil)
            let Vc = board.instantiateInitialViewController() as! VoiceTypeController
            Vc.delegate = self
            Vc.sexStr = recoderLabel.text!
            navigationController?.pushViewController(Vc, animated: true)
        }
    }
}

extension NewSettingController : VoiceTypeControllerDelegate {
    func voiceTypeController(sex: String) {
        recoderLabel.text = sex
    }
}
